﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using DONGACS.Common;
using DONGACS.DAO.Base;
using DONGACS.Domain;

namespace DONGACS.DAO
{
    public class JobTitlesDao : BaseDao<JobTitles>
    {
        //lấy tất cả JobTitles  
        public IList<JobTitles> GetAllJobTitles()
        {
            CommandText = "Select * From TB_JobTitles P Where P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            IList<JobTitles> list = CollectionHelper.ConvertTo<JobTitles>(table);
            return list;
        }


        //Lấy JobTitles theo ID
        public JobTitles GetJobTitlesById( string id)
        {
            CommandText = "Select * From TB_JobTitles P Where P.ID = " + id + " and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            JobTitles jobTitles = table.Rows.Count != 0 ? CollectionHelper.CreateItem<JobTitles>(table.Rows[0]) : null;

            return jobTitles;
        }

        public JobTitles GetJobTitleByName(string jobTitleName)
        {
            CommandText = "Select * From TB_JobTitles P Where P.JobTitle = N'" + jobTitleName + "' and P.IsDelete = 0";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            JobTitles jobTitles = table.Rows.Count != 0 ? CollectionHelper.CreateItem<JobTitles>(table.Rows[0]) : null;

            return jobTitles;
        }

        public bool AddNewJobTitles(JobTitles jobTitles)
        {
            return Insert("TB_JobTitles", jobTitles);
        }

        public bool AddNewJobTitles(JobTitles jobTitles, ref int idReturn)
        {
            return Insert("TB_JobTitles", jobTitles, ref idReturn);
        }

        public bool Update(JobTitles jobTitles)
        {
            return Update("TB_JobTitles", jobTitles);
        }

        public bool ShiftDelete(string id)
        {
            return this.ShiftDelete<JobTitles>("TB_JobTitles", id);
        }

        public bool Delete(string id)
        {
            return this.Delete<JobTitles>("TB_JobTitles", id);
        }
    }
}
